#include<iostream>
#include<queue>
using namespace std;
int BFS(int map[][200], int visit[],int n)
{
	int sum = 0;
	queue<int> q;
	int i = 0;
	for (i; i < n; i++)
	{
		if (visit[i] == 0)
		{
			sum++;
			q.push(i);
			visit[i] = 1;
			while (!q.empty())
			{
				i = q.front();
				q.pop();
				int j = 0;
				for (j; j < n; j++)
				{
					if (map[i][j] == 1&&visit[j]==0)
					{
						visit[j] = 1;
						q.push(j);
					}
				}
			}
		}
	}
	return sum;
}
int main()
{
	int map[200][200] = { 0 };
	int visit[200] = { 0 };
	int n;
	cin >> n;
	int i = 0;
	for (i; i < n; i++)
	{
		int j = 0;
		for (j; j < n; j++)
		{
			cin >> map[i][j];
		}
	}
	cout << BFS(map,visit, n);
}